classdef LibLinear ...
        < SupportVectorMachine ...
        & BinaryClassClassifier ...
        & Modelable
    %LIBLINEAR Summary of this class goes here
    %   Detailed explanation goes here
    
    properties ( SetAccess = protected )
        cost = 1
    end
    
    methods % Set methods
        function [  ] = setCost( this, cost )
            if nargin == 1
                this.cost = 1;
            end
            if nargin == 2
                this.cost = cost;
            end
        end
    end
    
    methods
        function [ this ] = LibLinear( name )
            if nargin == 0
                this.setName('liblinear');
            end
            if nargin >= 1
                this.setName(name);
            end
        end
    end
    
    methods
        function [  ] = build( this, X, Y )
            optionString = ['-s 1 -c ', num2str(this.cost), ...
                this.genWeightOption(Y), ' -q'];
            this.model = lsvmtrain(Y, sparse(X), optionString);
        end
        
        function [ result ] = apply( this, X, Y )
            [result.Y_hat, ~, result.Y_out] = lsvmpredict(Y, sparse(X), this.model);
            if all(result.Y_hat.*result.Y_out <= 0)
                result.Y_out = -result.Y_out;
            end
        end
    end
    
end

